<article class="" id="post-">
<header class="entry-header">
<h1 class="entry-title">jQuery.globalEval()</h1>
<div class="entry-meta">
						所属分类：<span class="category"><a href="/category/utilities/">工具类</a></span>
<span class="pull-right">英文文档：<a href="https://api.jquery123.com/jQuery.globalEval/" target="_blank">jQuery.globalEval()</a></span>
</div><!-- .entry-meta -->
</header><!-- .entry-header -->
<!-- .entry-header -->
<div class="entry-content">
<article class="entry method" id="jQuery-globalEval1"><h2 class="section-title">
<span class="name">jQuery.globalEval( code )</span><span class="returns">返回: <a href="/Types/#"></a></span>
</h2>
<div class="entry-wrapper">
<p class="desc"><strong>描述: </strong>在全局上下文下执行一些JavaScript代码。</p>
<ul class="signatures"><li class="signature" id="jQuery-globalEval-code">
<h4 class="name">
<span class="version-details">添加的版本: <a href="/category/version/1.0.4/">1.0.4</a></span>jQuery.globalEval( code )</h4>
<ul><li>
<div><strong>code</strong></div>
<div>类型: <a href="/Types/#String">String</a>
</div>
<div>用来执行的JavaScript代码。</div>
</li></ul>
</li></ul>
<div class="longdesc" id="entry-longdesc">
<p>此方法的表现不同于正常使用的JavaScript <code>eval()</code>，因为它是在全局上下文下执行（这对加载外部动态脚本很重要）。</p>
</div>
<section class="entry-examples" id="entry-examples"><header><h2 class="underline">例子:</h2></header><div class="entry-example" id="example-0">
<h4><span class="desc">在全局上下文中执行脚本。</span></h4>
<div class="syntaxhighlighter javascript ">
<table>
<tbody>
<tr>
<td class="gutter">
<div class="line n1">1</div>
<div class="line n2">2</div>
<div class="line n3">3</div>
<div class="line n4">4</div>
<div class="line n5">5</div>
</td>
<td class="code">
<pre><div class="container"><div class="line"><code><span class="function"><span class="keyword">function</span> <span class="title">test</span><span class="params">()</span>{</span></code></div></div><div class="container"><div class="line"><code>    jQuery.globalEval(<span class="string">"var newVar = true;"</span>)</code></div></div><div class="container"><div class="line"><code>    }</code></div></div><div class="container"><div class="line"><code>    test();</code></div></div><div class="container"><div class="line"><code>    <span class="comment">// newVar === true</span></code></div></div></pre>
</td>
</tr>
</tbody>
</table>
</div>
</div></section>
</div></article> </div>
</article>